
import unittest 
import person

class Team(object):
    def __init__(self,name = None):
        self._name = name
        self._members = []
        
    def add_member(self,person):
        self._members.append(person)
        
    def remove_member(self,person):
        self._members.remove(person)
        
    def __len__(self):
        return len(self._members)
        
    def __iter__(self):
        """
        this method make this object an "Enumerable"
        you can think __iter__ as "GetEnumerator" function in C#'s IEnumerable interface
        """
        return iter(self._members)
    
    def __eq__(self,rhs):
        if rhs is None:
            return False
        elif self is rhs:
            return True
        elif isinstance(rhs,Team):
            return (self._name == rhs._name) and (self._members == rhs._members) 
        else:
            return False
        
    def __ne__(self,rhs):
        return not self == rhs
    
class TestTeam(unittest.TestCase):
    def test_iter(self):
        num_persons = 4
        src_persons = [person.Person(ssn=x,name="name%d"%x) for x in range(num_persons)]
        
        ateam = Team("test")
        for aperson in src_persons:
            ateam.add_member(aperson)
            
        # ------------ check
        self.assertEqual(num_persons,len(ateam))
        self.assertEqual(src_persons,[x for x in ateam])
        
if __name__ == "__main__":
    unittest.main()
            
        
        
        
        
        
        
        
        
